/*
			method: 请求方式 get post
			url: 请求地址
			params：接口传参
			token: token
			success: 成功的函数
			ContentType: 请求头数据格式
		*/
		function ajax({method, url, params, token, resolve, ContentType}) {
			return new Promise((resolve, reject) => {
			let xhr = new XMLHttpRequest()
			let str = ""
			for(let i in params) {
				console.log(i, params[i])
				str += `${i}=${params[i]}&`
			}
			console.log(str)
			if (method == "get") {
				xhr.open(method, url + "?" + str)
				if (token) {
					xhr.setRequestHeader("token", token)
				}
				xhr.send()
			}else if (method == "getOther") {
				let val = ''
				for(let j  in params) {
					val = params[j]
				}
				xhr.open("get", url + "/" + val )
				if (token) {
					xhr.setRequestHeader("token", token)
				}
				xhr.send()
			}else if (method == "post") {
				xhr.open(method, url)
				if (token) {
					xhr.setRequestHeader("token", token)
				}
				if(ContentType == "application/x-www-form-urlencoded") {
					xhr.setRequestHeader("Content-Type", ContentType)
					xhr.send(str)
				}else if (ContentType == "application/json"){
					// json
					xhr.setRequestHeader("Content-Type", ContentType)
					xhr.send(JSON.stringify(params))
				}else{
					let fileParam = new FormData()
					for(let i in params) {
						fileParam.append(i, params[i])
					}
					xhr.send(fileParam)
				}

			}
			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4) {
					let res = JSON.parse(xhr.responseText)
					if (res.code == 200) {
						resolve.log(res)
					}else{
						reject(res)
					}
				}
			}
		})
	}